Read in packages

library(tidyverse)
library(here)
library(plotly)

Read in X2 data and combine

x2a <- read_csv(here("docs/IBMR_X2_SF2025_input.csv")) %>%
  mutate(hydro = "AdjHist")
x2b <- read_csv(here("docs/IBMR_X2_SF2022MED_input.csv")) %>%
  mutate(hydro = "2022MED")
x2 <- bind_rows(x2a, x2b)

x2_long <- x2 %>%
  pivot_longer(cols = 3:14, values_to = "x2", names_to = "month") %>%
  mutate(month = as.numeric(month)) %>%
  mutate(month_abb = factor(month.abb[month], levels = month.abb)) %>%
  mutate(scenario = forcats::fct_relevel(scenario,  c("StatusQuo", "MaxDS_Even","MaxDS_Hist", "SummerFall_Even", "Summer_Even", "Summer_Even_AltSMSCG",
                                                      "SummerFall_Hist", "Summer_Hist", "June", "MaxWater", "MaxWater_noSMSCG"))) 

x2_summerfall <- x2_long %>% filter(month > 5 & month<11)

Plot data

plot_x2 <- ggplot() +
    # geom_point(data = x2_summerfall, aes(x = year, y = x2, color = scenario, shape = scenario))+
    geom_line(data = x2_summerfall, aes(x = year, y = x2, color = scenario, linetype = scenario), alpha = 0.9)+
    # scale_shape_manual(values = c(20, 0, 18, 6, 8, 9, 10, 23, 1, 13, 14))+
    viridis::scale_color_viridis(discrete = TRUE, option = "turbo") + 
    scale_x_continuous(breaks = seq(1995, 2014, 1))+ 
    scale_y_continuous(breaks = seq(55, 95, 10)) + 
    facet_wrap(month_abb~hydro, nrow = 5) + 
    labs(y = "X2 (km)")+
    theme_bw() +
    theme(axis.text  = element_text(size = 11),
          axis.text.x = element_text(angle = 90))
ggplotly(plot_x2)